﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="/lib/html5shiv.js"></script>
<script type="text/javascript" src="/lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="/h-ui.admin/css/style.css" />
<link rel="stylesheet" href="/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">

    <script type="text/javascript" src="/easyui/jquery.min.js"></script>
<!--[if IE 6]>
<script type="text/javascript" src="/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<style>
	.help-block{
		color: #ff0017;
	}
	.uberror{
		height:20px;
		overflow: hidden;
		margin-top:10px;
		color: red;
	}
</style>
<![endif]-->
</head>
<body class="easyui-layout">
<div data-options="region:'center',border:false" style="padding:2px;height: auto">
	<table class="table">
		<tr>
			<td width="20%" class="va-t"><ul id="treeDemo" class="ztree"></ul></td>
			<td width="79%" style="margin-top: 200px" class="va-t">
				<form action="" method="post" class="form form-horizontal" style="width: 75%" id="form-menu-add">
					<div class="row cl">
						<label class="form-label col-xs-6 col-sm-3"><span class="c-red">*</span> ${name}</label>
						<div class="formControls col-xs-6 col-sm-6">
							<input type="text" class="input-text" value="" placeholder="" id="catalog_name" name="catalog_name">
						</div>
					</div>
					<#if isflag=='Y'>
                        <div class="row cl">
                            <label class="form-label col-xs-6 col-sm-3"><span class="c-red">*</span> ${rout}：</label>
                            <div class="formControls col-xs-6 col-sm-6">
                                <input type="text" class="input-text" value="" placeholder="" id="catalog_path" name="catalog_path">
                            </div>
                        </div>
					</#if>
                    <#if isflag=='N'>
                        <div class="row cl">
                            <label class="form-label col-xs-6 col-sm-3"><span class="c-red">*</span> ${icon}：</label>
                            <div class="formControls col-xs-6 col-sm-6">
                                <input type="text" class="input-text" value="" placeholder="" id="catalog_icon" name="catalog_icon">
                            </div>
                        </div>
                    </#if>
					<div class="row cl">
						<div class="col-9 col-offset-2">
							<input class="btn btn-primary radius" type="submit" id="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
						</div>
					</div>
                    <div class="row cl">
                        <div class="formControls col-xs-8 col-xs-offset-3">
                            <div class="uberror"></div>
                        </div>
                    </div>
				</form>
			</td>
		</tr>
	</table>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<script type="text/javascript" src="/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">
	var setting = {
		view: {
			dblClickExpand: false,
			showLine: false,
			selectedMulti: false
		},
		data: {
			simpleData: {
				enable: true,
				idKey: "id",
				pIdKey: "pId",
				rootPId: ""
			}
		},
		callback: {
			//点击菜单中文名称
			beforeClick: function (treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("tree");
				if (treeNode.isParent || treeNode.pId == '-1') {
					window.location.href = "/admin/admin-menu-manage?id=" + treeNode.id + "&isflag=Y";
					return false;
				}
			}
		}
	};
	var zNodes = [
	<#list zNodes as znodes>
		{id:${znodes.id},pId:${znodes.pId},name:"${znodes.name}",open:${znodes.open?c}}<#if znodes_has_next>,</#if>
	</#list>
	];
	$(document).ready(function(){
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
	});
    $(document).ready(function () {
        $('#form-menu-add').validate({
            errorElement: 'span',
            errorClass: 'help-block',
            rules: {
                catalog_name: {
                    required: true
                }
            },
            messages: {
                catalog_name: {
                    required: "请输入菜单名！"
                }
            },
            errorPlacement: function (error, element) {
                if (!$(element).hasClass("noErrorMessage"))
                    $(element).closest('.formControls').append(error);
            },
            highlight: function (element) {
                $(element).closest('.formControls').addClass('has-error has-feedback');
            },
            unhighlight: function (element, errorClass, validClass) {
                $(element).closest('.formControls').removeClass('has-error');
            },
            success: function (label, element) {
                if ($(label)) $(label).remove();
            },
            submitHandler: function (form) {
                var name = $('#catalog_name').val();
                var parentId = '${parent_id}';
                var isFlag = '${isflag}';
                var other = '';
                if(isFlag=='Y'){
                    other = $('#catalog_path').val();
                }else if(isFlag=='N'){
                    other = $('#catalog_icon').val();
                }
                $.ajax({
                    type: 'POST',
                    url: '/admin-menu-save',
                    data: {name: name, other: other, flag: isFlag, parentId: parentId, TM: new Date().getTime()},
                    async: false,
                    success: function (result) {
                        if ("success" == result.result) {
                            window.location.href = "/admin/admin-menu-manage?id=" + parentId;
                        } else if ("error" == result.result) {
                            $(".uberror").html("添加出错，请联系开发人员");
                        }
                    }
                })
            }
        })
    })
</script>
</body>
</html>